#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        long long n,m,l,v;
        cin>>n>>m>>l>>v;
        long long d[n+1],v0[n+1],a[n+1];
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v0[i]>>a[i];
        }
        long long p[m+1];
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        vector<pair<int,int> > vec;
        for(int i=1;i<=n;i++){
            int lm=lower_bound(p+1,p+m+1,d[i])-p;
            if(lm>m)continue;
            if(a[i]==0){
                if(v0[i]>v){
                    vec.push_back({m,lm});
                }
            }else if(a[i]>0){
                if(v0[i]>v){
                    vec.push_back({m,lm});
                }else{
                    long long x=(v*v-v0[i]*v0[i])/(2*a[i])+d[i]+1;
                    lm=lower_bound(p+1,p+m+1,x)-p;
                    if(lm<=m){
                        vec.push_back({m,lm});
                    }
                }
            }else{
                if(v0[i]<=v)continue;
                a[i]=-a[i];
                long long x=(v0[i]*v0[i]-v*v-1)/(2*a[i])+1+d[i];
                int rm=lower_bound(p+1,p+m+1,x)-p-1;
                if(lm<=rm){
                    vec.push_back({rm,lm});
                }
            }
        }
        sort(vec.begin(),vec.end());
        int pnt=-1,ans=0;
        for(int i=0;i<vec.size();i++){
            if(pnt<vec[i].second){
                pnt=vec[i].first;
                ans++;
            }
        }
        cout<<vec.size()<<" "<<m-ans<<endl;
    }
    return 0;
}